package com.paw.hand.gateway.config;

import com.paw.hand.gateway.interceptor.RouteInterceptor;
import com.paw.hand.gateway.interceptor.TokenInterceptor;
import org.bouncycastle.cms.PasswordRecipient.PRF;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lvzihai
 * @date 2021/6/16
 **/
@Configuration
public class WebConfiguration implements WebMvcConfigurer {

  @Autowired
  private TokenInterceptor tokenInterceptor;

  @Autowired
  private RouteInterceptor routeInterceptor;

  @Bean
  @LoadBalanced
  @ConditionalOnClass(RestTemplate.class)
  public RestTemplate restTemplate(){
    return new RestTemplate();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns("/anonymous/**");
    registry.addInterceptor(routeInterceptor).addPathPatterns("/**");

  }

}
